
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        人员添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="css/main.css" media="all">
    <!-- 引入ElementUI样式 -->
    <link rel="stylesheet" href="/css/index.css">
    <style>
        .imgs{display: none;}
        input[type="file"]{
            width: 50px;
            height:50px;
            border-radius: 100%;
            opacity:0;
            cursor:pointer;
            border: 1px solid red;
            position: absolute;
        }
    </style>

</head>
<body>
<div id="app">
<div class="x-body" style="margin-top: 15px;">
    <form class="layui-form layui-form-pane" action="" id="add">
        <blockquote class="layui-elem-quote">
            <div >
                <img src="./images/tx.jpg" class="layui-circle svgIcon" style="width:50px;height:50px;float:left" id="pimages" name="pimages"   alt="个人头像" >
                <input id="avatar"   name="image" required="" type="hidden" value="./images/svg.jpg" >
                <dl style="margin-left:55px; color:#019688">
                    <dt><span >ADMIN</span> <span ></span></dt>
                    <dd style="margin-left:0">这家伙很懒，什么也没有留下</dd>
                </dl>
            </div>
        </blockquote>
        <el-form :model="personal" :rules="rules" ref="personalFormRef" label-width="120px" class="demo-ruleForm">
            <el-form-item label="用户名" prop="name">
                <el-input v-model="personal.loginName"></el-input>
            </el-form-item>
            <el-form-item label="电话号码" prop="telephone">
                <el-input v-model="personal.telephone"></el-input>
            </el-form-item>
            <el-form-item label="密码 " prop="password">
                <el-input v-model="personal.password" type="password"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="save()" style="text-align: center">保存</el-button>
                <el-button @click="clearAll()" style="text-align: center">重置</el-button>
            </el-form-item>
        </el-form>
    </form>
</div>
</div>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src="js/x-layui.js" charset="utf-8"></script>
<!--导入Vue依赖包-->
<script src="/js/vue.js" charset="utf-8"></script>
<!-- 引入Element组件库 -->
<script src="/js/index.js"></script>
<!--导入Axios依赖包-->
<script src="/js/axios.js" charset="utf-8"></script>
<script type="text/javascript">
    var  userId=sessionStorage.getItem("userId");
    var app = new Vue({
        el:"#app",
        data:{
            personal:{},
            rules: {
                name: [
                    { required: true, message: '请输入用户名', trigger: 'blur' },
                    { max: 50, message: '长度小于17个字符', trigger: 'blur' }
                ],
                code: [
                    { required: true, message: '请输入用户密码', trigger: 'blur' },
                    { min: 4,max: 8, message: '长度必须大于4、小于8个字符', trigger: 'blur' }
                ],
            }
        },
        methods:{
            //表达重置
            clearAll() {
                this.$refs.personalFormRef.resetFields();
            },
            findById(){
                axios.get("/estate/manager/findById?id="+userId).then((res)=>{
                    this.personal = res.data.data;
                });
            },
            // 修改
            save(){
                axios.post("/estate/manager/update/",this.personal).then((res)=>{
                    if(res.data.flag){
                        this.$message({
                            message: res.data.message,
                            type: 'success'
                        });
                    }
                });
            },

        },
        created:function(){
            layui.use(['element','layer','form'], function(){
                $ = layui.jquery;//jquery
                lement = layui.element();//面包导航
                layer = layui.layer;//弹出层
                form = layui.form();
            });
            this.findById();
        }
    });
</script>
<script>
    // layui.use(['element','layer','form'], function(){
    //     $ = layui.jquery;//jquery
    //     lement = layui.element();//面包导航
    //     layer = layui.layer;//弹出层
    //     form = layui.form()
    //
    //     //监听提交
    //     form.on('submit(add)', function(data){
    //         var name=$("input[name='name']").val();
    //
    //         if(name==""){
    //             layer.msg('用户名不能为空',{icon:5,time:2000});return false;
    //         }
    //
    //         var data=data.field;
    //         $.ajax({
    //             type:"post",
    //             url:"xxx",
    //             data:data,
    //             dataType:"json",
    //             success:function(data)
    //             {
    //                 //alert(1);
    //                 if(data.status==1)
    //                 {
    //                     layer.msg(data.info, {icon: 6,time:2000},function () {
    //                         window.parent.location.reload();
    //                         var index = parent.layer.getFrameIndex(window.name);
    //                         parent.layer.close(index);
    //                     });
    //                     return false;
    //
    //                 }
    //                 else{
    //                     layer.msg(data.info,{icon:5,time:2000});return false;
    //                 }
    //             }
    //
    //         });
    //
    //     });
    //
    // })
</script>
<!--栏目缩略图上传-->
<script>
    function upload(obj,id){
        var formData = new FormData();
        formData.append('images', $('#previewImg')[0].files[0]);
        formData.append('id', id);
        layer.msg('图片上传中', {icon: 16});
        $.ajax({
            type:"post",
            processData: false,
            contentType: false,
            url:"xxx",
            data:formData,
            success:function(data){
                if(data.status == 1){
                    console.log(data.image_name);
                    layer.closeAll('loading');
                    //layer.msg(data.info,{icon:1,time:1000});
                    $("#pimages").attr('src',data.image_name);
                    $("#avatar").val(data.image_name);
                    $(".imgs").show();
                    return false;
                }else{
                    layer.msg(data.info,{icon:2,time:1000});
                }
            }
        });
    }
</script>

</body>
</html>